﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Polymod
{
    internal class OnSetInvoker : IInvoker
    {
        readonly IInvoker _inner;
        readonly Delegate _action;

        public object GetValue(IModel target)
        {
            return _inner.GetValue(target);
        }

        public void SetValue(IModel target, object value)
        {
            if (!IsReadonly) _inner.SetValue(target, value);
            _action.DynamicInvoke(target);
        }

        public Type ReturnType
        {
            get { return _inner.ReturnType; }
        }

        public bool IsReadonly
        {
            get { return _inner.IsReadonly; }
        }

        public string Name
        {
            get { return _inner.Name; }
        }

        public OnSetInvoker(IInvoker inner, Delegate action)
        {
            _inner = inner;
            _action = action;
        }

        public IInvoker Clone()
        {
            return new OnSetInvoker(_inner.Clone(), _action);
        }
    }


}
